package com.fengmi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 作者：陈学虎
 * 时间：2021/7/6 0006 下午 7:41
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    private ApiInfo apiInfo() {


        Contact contact = new Contact("陈学虎", "http://www.wendaoxueyuan.com", "2511308034@qq.com");


        return new ApiInfoBuilder().title("锋迷铺子运营平台接口文档")
                .description("锋迷铺子运营平台接口文档描述")
                .version("1.0.0")
                .contact(contact)
                .build();


    }

    @Bean
    public Docket createRestApi(Environment environment) {


        //指定swagger开放的环境
        Profiles profiles = Profiles.of("dev","sit");

        boolean enable = environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.fengmi.controller")) //这里写的是API接口所在的包位置
                .paths(PathSelectors.any())
                .build();
    }

}
